<?php

declare(strict_types=1);

namespace app\shop\controller\admin\user;

use think\Request;
use think\facade\Db;
use sheep\controller\traits\Crud;
use sheep\controller\Backend;
use sheep\exception\SheepException;
use app\shop\model\user\Coupon as UserCouponModel;

/**
 * 用户优惠券
 */
class Coupon extends Backend
{
    public function initialize()
    {
        $this->model = new UserCouponModel;
    }


    /**
     * 用户优惠券列表
     *
     * @return \think\Response
     */
    public function list($user_id)
    {
        $userCoupons = $this->model->sheepFilter()->with('coupon')->where('user_id', $user_id)
            ->order('id', 'desc')->paginate(request()->param('list_rows', 10));

        return success('获取成功', $userCoupons);
    }


    /**
     * 优惠券发放列表
     *
     * @return void
     */
    public function couponList($coupon_id)
    {
        $coupons = $this->model->sheepFilter()->with(['user', 'order'])
            ->where('coupon_id', $coupon_id)
            ->paginate(request()->param('list_rows', 10));

        return success('获取成功', $coupons);
    }

}
